home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / others.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  3KB  |  155 lines

  1. /***   [others.c]
  2. *
  3. *    その他いろいろ ヨ        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <jctype.h>
  12. #include <ctype.h>
  13. #include <bios.h>
  14. #include <snd.h>
  15. #include <mos.h>
  16. #include "graph.h"
  17.  
  18. extern int    PAL_Black;
  19. static int    _TIMER_end;
  20.  
  21. /* fpathで示されるフルパスを文字数がnx以下になるようにし, bufへ格納 */
  22. /* 戻り値は, bufへ格納した先頭のオフセット                            */
  23. int Cont_path(const char *fpath, int nx, char *buf) {
  24.     int        len, ret;
  25.     
  26.     if ((len = strlen(fpath)) > nx) {
  27.         int        n = 0;
  28.         
  29.         while (n <= nx - 5)            /* nx - <ピリオドの数> - 2 */
  30.             while (fpath[len - ++n] != '\\');
  31.         if (n > nx - 5)
  32.             while (fpath[len - --n] != '\\');
  33.         ret = len - n;
  34.     } else {
  35.         ret = 0;
  36.     }
  37.     
  38.     if (ret > 0) {
  39.         strncpy(buf, fpath, 2);
  40.         strcpy(buf + 2, "...");
  41.         strcpy(buf + 5, fpath + ret);
  42.     } else {
  43.         strcpy(buf, fpath);
  44.     }
  45.     
  46.     return ret;
  47. }
  48.  
  49. /* strで示される文字列を小文字に modeが1のとき先頭だけ大文字に (日本語対応) */
  50. void strlow(int mode, unsigned char *str) {
  51.     int        i = 0;
  52.     
  53.     if (mode && str[i]) {
  54.         if (iskanji(*((unsigned char *)str + i)))
  55.             i++;
  56.         else
  57.             str[i] = toupper(str[i]);
  58.         i++;
  59.     }
  60.     while (str[i]) {
  61.         if (iskanji(*((unsigned char *)str + i)))
  62.             i++;
  63.         else
  64.             str[i] = tolower(str[i]);
  65.         i++;
  66.     }
  67. }
  68.  
  69. /* 数値valにコンマを付けて, 文字列としてbufへ格納 */
  70. void Konma(unsigned val, char *buf) {
  71.     int        i, flag;
  72.     
  73.     if (i = val / 1000000) {
  74.         sprintf(buf, "%3u,", i);
  75.         flag = 1;
  76.     } else {
  77.         sprintf(buf, "    ");
  78.         flag = 0;
  79.     }
  80.     if ((i = (val % 1000000) / 1000) != 0 || flag != 0) {
  81.         if (flag)
  82.             sprintf(buf + 4, "%03u,", i);
  83.         else
  84.             sprintf(buf + 4, "%3u,", i);
  85.         
  86.         flag = 1;
  87.     } else {
  88.         sprintf(buf + 4, "    ");
  89.     }
  90.     if (flag)
  91.         sprintf(buf + 8, "%03u", val % 1000);
  92.     else
  93.         sprintf(buf + 8, "%3u", val % 1000);
  94. }
  95.  
  96. /* y:西暦(-1980) m:月 d:日 として曜日を返す万年カレンダー (うるう年にも対応ヨ) */
  97. const unsigned char *Getyoubi(int y, int m, int d) {
  98.     int        days;
  99.     static const short    Month[] = {
  100.         0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
  101.     };
  102.     static const unsigned char    Youbi[][3] = {
  103.         "木", "金", "土", "日", "月", "火", "水"
  104.     };
  105.     
  106.     days = (y + 11) / 4 * 1461 + ((y + 11) % 4) * 365 - 365;    /* 11 = 1980 - 1969 */
  107.     days += Month[m - 1] + d - 1;
  108.     if (!((1980 + y) % 4) && m >= 3)
  109.         days++;
  110.     
  111.     return Youbi[days % 7];
  112. }
  113.  
  114. void TIMER_set(int a) {
  115.     extern void    _TIMER_reset(int);
  116.     extern void    _TIMER_sub(void);
  117.     
  118.     _TIMER_end = 0;
  119.     _TIMER_reset(a);
  120.     SND_int_timer_a_set((void *)_TIMER_sub);
  121.     SND_fm_timer_a_set(1, 500);        /* 10ms */
  122. }
  123.  
  124. int TIMER(void) {
  125.     int        r = 0;
  126.     extern int    _TIMER_flag;
  127.     
  128.     if (_TIMER_end)    return 1;
  129.     
  130.     if (_TIMER_flag) {
  131.         SND_fm_timer_a_set(0, 0);
  132.         SND_int_timer_a_set(NULL);
  133.         _TIMER_end = 1;
  134.         r = 1;
  135.     }
  136.     
  137.     return r;
  138. }
  139.  
  140. int strLE(const char *str, int l) {
  141.     int        i = 0;
  142.     
  143.     while (i < l && str[i]) {
  144.         if (iskanji(((const unsigned char *)str)[i])) {
  145.             if (i + 1 < l)
  146.                 i++;
  147.             else
  148.                 break;
  149.         }
  150.         i++;
  151.     }
  152.     
  153.     return i;
  154. }
  155.